package main

import (
	"fmt"
	"gin-YiStudio-V1/common"
	"gin-YiStudio-V1/config"
	_ "gin-YiStudio-V1/docs"
	"gin-YiStudio-V1/router"
	"gin-YiStudio-V1/util/validatorUtils"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	"os"
)

// @title Golang Esign API
// @version 1.0
// @description  Golang api of demo
// @termsOfService http://github.com

// @contact.name API Support
// @contact.url http://www.cnblogs.com
// @contact.email ×××@qq.com

//@host 127.0.0.1:9090
func main() {

	common.Init()
	defer common.DB.Close()

	engine := gin.Default()
	//自定义校验器

	//validate := validator.New()
	//_ = validate.RegisterValidation("mustBig", validatorUtils.MustBig)

	//自定义注解其他写法
	if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
		_ = v.RegisterValidation("mustBig", validatorUtils.MustBig)
		v.RegisterValidation("checkSpecialNum", validatorUtils.CheckSpecialNum)
	}

	// 文档界面访问URL
	// http://127.0.0.1:9090/swagger/index.html
	engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	router.InitUserRouter(engine)
	router.InitOtherRouter(engine)

	fmt.Println("|-----------------------------------|")
	fmt.Println("|    " + config.AppName + "-" + config.AppMode + "    |")
	fmt.Println("|-----------------------------------|")
	fmt.Println("|  Go Http Server Start Successful  |")
	fmt.Println("|    Port" + config.AppPort + "     Pid:" + fmt.Sprintf("%d", os.Getpid()) + "        |")
	fmt.Println("|-----------------------------------|")
	fmt.Println("")
	//启动服务
	err := engine.Run(":9090")
	if err != nil {
		panic(err)
	}

}
